package com.yuntcm.group6.med_booking.controller;


import com.yuntcm.group6.med_booking.entity.Doctor;
import com.yuntcm.group6.med_booking.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/doctor")
public class DoctorController {
    @Autowired
    private DoctorService doctorService;

    @GetMapping
    public List<Doctor> findAll() {
        return doctorService.listAllDoctor();
    }
//    新增查询方法，使用@RequestParam接收查询参数
    @GetMapping("/search")
    public List<Doctor> searchDoctors(
            @RequestParam(required = false)String keyword,
            @RequestParam(required = false) Integer deptId
    ){
        return doctorService.searchDoctors(keyword, deptId);
    }


    @PostMapping("/add")
    public boolean add(@RequestBody Doctor doctor) {
        return doctorService.save(doctor);
    }
    @PostMapping("/update")
    public boolean update(@RequestBody Doctor doctor) {
        return doctorService.save(doctor);
    }
    @DeleteMapping("/delete/{id}")
    public boolean delete(@PathVariable int id) {
        return doctorService.removeById(id);

    }


}
